//
//  FDMMasterCollectionViewCellTrack.m
//  Entertainment
//
//  Created by dllo on 16/4/23.
//  Copyright © 2016年 付冬梅. All rights reserved.
//

#import "FDMMasterCollectionViewCellTrack.h"
#import "FDMMasterTrackModel.h"

@interface FDMMasterCollectionViewCellTrack ()

@property (nonatomic, retain) UIImageView *titleImage;
@property (nonatomic, retain) FDMBaseLabel *titleLabel;
@property (nonatomic, retain) FDMBaseLabel *playTimes;
@property (nonatomic, retain) FDMBaseLabel *tracksLabel;

@end
@implementation FDMMasterCollectionViewCellTrack

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createCellOfTrack];
    }
    return self;
}

- (void)dealloc {
    [self.titleImage release];
    [self.titleLabel release];
    [self.tracksLabel release];
    [self.playTimes release];
    [super dealloc];
}

- (void)createCellOfTrack {
    self.titleImage = [[UIImageView alloc] init];
    [self.contentView addSubview:self.titleImage];
    [self.titleImage release];
    self.titleLabel = [[FDMBaseLabel alloc] init];
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel release];
    self.playTimes = [[FDMBaseLabel alloc] init];
    [self.contentView addSubview:self.playTimes];
    [self.playTimes release];
    self.tracksLabel = [[FDMBaseLabel alloc] init];
    [self.contentView addSubview:self.tracksLabel];
    [self.tracksLabel release];
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    [super applyLayoutAttributes:layoutAttributes];
    [self.titleImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(10);
        make.left.equalTo(self.contentView.mas_left);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-10);
        make.width.mas_equalTo(@80);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(10);
        make.left.equalTo(self.titleImage.mas_right).with.offset(10);
        make.bottom.equalTo(self.contentView.mas_top).with.offset(30);
        make.right.equalTo(self.contentView.mas_right).with.offset(10);
    }];
    
    self.playTimes.font = [UIFont systemFontOfSize:14];
    self.playTimes.textColor = [UIColor grayColor];
    [self.playTimes mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_bottom).with.offset(-30);
        make.left.equalTo(self.titleImage.mas_right).with.offset(10);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-10);
        make.width.equalTo(@200);

    }];
    
    self.tracksLabel.textColor = [UIColor grayColor];
    self.tracksLabel.font = [UIFont systemFontOfSize:14];
    [self.tracksLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_bottom).with.offset(-90);
        make.left.equalTo(self.titleImage.mas_right).with.offset(10);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-10);
        make.width.equalTo(@100);
    }];
    
}

- (void)setTrackModel:(FDMMasterTrackModel *)trackModel {
    if (_trackModel != trackModel) {
        [_trackModel release];
        _trackModel = [trackModel retain];
        [self.titleImage sd_setImageWithURL:[NSURL URLWithString:_trackModel.coverMiddle] placeholderImage:PLACEHOLDER_IMAGE];
        self.titleLabel.text = _trackModel.title;
        self.playTimes.text = [NSString stringWithFormat:@"播放次数: %@", _trackModel.playTimes];
        self.tracksLabel.text = [_trackModel.tracks stringValue];
        
    }
}

@end
